package com.goatrock.media.thisway.common.util;

import com.goatrock.media.thisway.common.constants.ApplicationConstants;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.apache.log4j.Logger;

public class BeanLocator {
    private BeanLocator(){}
    private static Logger logger = Logger.getLogger(BeanLocator.class);

    public static Object getBean(String beanName){
        return BeanLocator.getBean(beanName, ApplicationConstants.SPRING_LOCATION );
    }

    public static Object getBean(String beanName, String springLoc){
        logger.debug("Attempting to load bean: "+beanName);

        ApplicationContext context = new ClassPathXmlApplicationContext(springLoc);
        BeanFactory factory = context;

        Object beanObj = factory.getBean(beanName);

	return beanObj;
    }
}